// page/member/income.js
Page({
  data: {
    isHide: 0,
    balance: "0",   //余额 
    money: "",   //提现金额
    record: [],  //收入记录
    rules: "充值提现规则说明"   //充值提现规则说明
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    var app = getApp()
    var uid = wx.getStorageSync('uid');
    wx.request({
      url: app.globalData.host + '&g=App&m=Member&a=receita', //仅为示例，并非真实的接口地址
      data: { uid: uid },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        console.log(res)
        if(res.data.status){
          that.setData({
            balance: res.data.user_money,
            record: res.data.list,
            isHide: 1,
          })
        }else{
          wx.showToast({
            title: res.data.msg,
            icon: 'success',
            duration: 2000
          })
        }
      
      }
    })
    // that.setData({
    //     isHide: 1,
    //     record: [
    //         {
    //             "orderNo": "05461496561",
    //             "orderTime": "2016.05.26 17:37",
    //             "orderBuyer": "13400604058",
    //             "orderPrice": "66"
    //         }
    //     ]
    // })
  },
   /**
    * 全部提现
    */ 
  allWithdrawal: function () {
      var that = this
      that.setData({
          money: that.data.balance
      })
  },
  /**
   * 超出余额时提示
  */
  isLargest(e) {
      var that = this
      that.setData({
          money: e.detail.value
      })
      if (parseFloat(that.data.money) > parseFloat(that.data.balance)){
          wx.showModal({
              title: '提示',
              content: '提现金额不得超出余额',
              showCancel: false
          })
      }
  },
 /**
  * 表单验证
 */
  formSubmit: function (e) {
      var that = this
      var money = e.detail.value.money
      var code = e.detail.value.code
      var app = getApp()
      var uid = wx.getStorageSync('uid');
      if (money.length < 1 ) {
          wx.showModal({
              title: '提示',
              content: '请输入提现金额或提现金额有误',
              showCancel: false
          })
          return false
      } else if (parseFloat(money) > parseFloat(that.data.balance)){
          wx.showModal({
              title: '提示',
              content: '提现金额不得超出余额',
              showCancel: false
          })
          return false
      // }else  if(code.length < 1){
      //     wx.showModal({
      //         title: '提示',
      //         content: '请输入短信验证码',
      //         showCancel: false
      //     })
      //     return false        
      } else if (parseFloat(money) <=0 ) {
            wx.showModal({
                title: '提示',
                content: '请输入正数',
                showCancel: false
            })
            return false        
      }else{
      
        wx.request({
          url: app.globalData.host + '&g=App&m=Member&a=receita', //仅为示例，并非真实的接口地址
          data: { uid: uid, money: money, is_w:1},
          header: {
            'content-type': 'application/json'
          },
          success: function (res) {
          
            if (res.data.status) {
              that.setData({
                balance: res.data.user_money,
                record: res.data.list,
              })
              wx.showToast({
                title: res.data.msg,
                icon: 'success',
                duration: 2000
              })
            } else {
              wx.showToast({
                title: res.data.msg,
                icon: 'success',
                duration: 2000
              })
            }

          }
        })          
      }
  },
  /**
   * 规则说明
   */ 
  rulesPopup: function () {
      wx.showModal({
          title: '充值提现规则说明',
          content: this.data.rules,
          showCancel: false
      })
  }
})